package myJs.components

import japgolly.scalajs.react._
import japgolly.scalajs.react.component.Scala.BackendScope
import japgolly.scalajs.react.extra.StateSnapshot
import japgolly.scalajs.react.vdom.all._
import myJs.Tool
import myJs.myPkg.jquery._

/**
 * Created by yz on 3/11/2020
 */
object InputInlineComponent {

  case class Props(state: StateSnapshot[String], label: String, name: String, show: Boolean = true,formJq:JQuery) {
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  class Backend(bs: BackendScope[Props, Unit]) {

    def didMount: Callback = {
      Callback {
        Tool.popover
      }
    }

    def didUpdate(p: Props): Callback = {
      Callback {
      }
    }

    def render(p: Props) = {

      val s = p.state.value
      div(`class` := "form-group",(display := "none").unless(p.show),
        label(`class` := "control-label col-sm-4",
          s"${p.label}", ":"
        ),
        div(`class` := "col-sm-8",
          PureInputComponent.Props(p.state, name = p.name,formJq = p.formJq).render,
        )
      )

    }

  }

  val Component = ScalaComponent.builder[Props].renderBackend[Backend].
    componentDidMount(x => x.backend.didMount).
    componentDidUpdate(x => x.backend.didUpdate(x.currentProps)).
    build

}



